package com.adb.dao;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class BaseDatabaseHelper extends SQLiteOpenHelper {

	static String name = "shudu.db";
	static CursorFactory cursorFactory = null;
	static int version = 39000;

	BaseDatabaseHelper(Context context, String name,
			CursorFactory cursorFactory, int version) {
		super(context, name, cursorFactory, version);
	}

	public BaseDatabaseHelper(Context context) {
		super(context, name, cursorFactory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// 所有表的创建过程都在这里进行
		// Called when the database is created for the first time.
		// 数据库第一次创建的时候运行
		SqlForDBCreate.iniDatabase(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion < 27000) {
			SqlForDBCreate.iniTable_GameDratf(db);// 2.6版本以下的需要新增草稿表
		}
	}

	@Override
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
		// 每次成功打开数据库后首先被执行
	}

	public void execSQL(String sql) {
		SQLiteDatabase db = getWritableDatabase();
		db.execSQL(sql);
	}

	/**
	 * 按sql查询数据
	 * 
	 * @param sql
	 * @return
	 */
	public Cursor Query(String sql) {
		SQLiteDatabase db = getReadableDatabase();
		Cursor cursor = db.rawQuery(sql, new String[] {});
		return cursor;
	}

	public void finalize() {
		close();
	}
}
